package com.ht.web_vr_home_tour_backend.obj.pojo;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ht.web_vr_home_tour_backend.obj.enums.PojType;
import com.ht.web_vr_home_tour_backend.obj.vo.PojInfoVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@ApiModel("项目信息")
@TableName("poj_info")
public class PojInfo {
    @TableId
    Long id;

    @ApiModelProperty("项目名称")
    String name;

    @ApiModelProperty("项目介绍（正文）")
    String description;

    @ApiModelProperty("项目类型")
    PojType pojType;

    @ApiModelProperty("项目创建时间")
    @TableField(fill = FieldFill.INSERT)
    LocalDateTime createTime;

    @ApiModelProperty("项目更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    LocalDateTime updateTime;

    @ApiModelProperty("项目归属用户")
    @TableField(fill = FieldFill.INSERT)
    Long createUser;

    public PojInfo() {
    }

    public PojInfo(PojInfoVo pojInfoVo) {
        if (StrUtil.isBlankIfStr(pojInfoVo.getId())) {
            this.id = null;
        } else {
            this.id = Long.parseLong(pojInfoVo.getId());
        }
        this.name = pojInfoVo.getName();
        this.description = pojInfoVo.getDescription();
        if (pojInfoVo.getPojType() != null) {
            for (PojType value : PojType.values()) {
                if (value.name().equals(pojInfoVo.getPojType())) {
                    this.pojType = value;
                }
            }
        }
    }
}
